package org.mozhu.zufang.system.group.repository;

import org.mozhu.mboot.core.data.BaseRepository;
import org.mozhu.zufang.system.group.entity.UserGroupRelation;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 用户分组关系 - 数据访问层接口
 *
 * @author mozhu
 */
public interface UserGroupRelationRepository extends BaseRepository<UserGroupRelation, Long> {

    UserGroupRelation findByGroupIdAndUserId(Long groupId, Long userId);

    @Query("select groupId from UserGroupRelation where userId=?1")
    List<Long> findGroupIds(Long userId);

    @Query("delete from UserGroupRelation r where " + "not exists (select 1 from Group g where r.groupId = g.id)")
    void clearDeletedGroupRelation();
}
